#include "canvas.h"
Canvas::Canvas(int width, int height):
    width_(width),height_(height),current_(0,0)
{
    surface_ = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width_,height_);
    cr_ = cairo_create(surface_);
}
Canvas::~Canvas()
{
    cairo_destroy(cr_);
    cairo_surface_write_to_png(surface_,"canvas.png");
}
Point Canvas::Draw(Shape* s)
{
    return current_ = s->Draw(cr_);
}
Dot::Dot(Point p):p_(p)
{
}
Point Dot::Draw(cairo_t* cr)
{
    return p_;
}
Line::Line(Point from, Point to):from_(from),to_(to)
{
}
Point Line::Draw(cairo_t* cr)
{
    cairo_move_to(cr, from_.x_, from_.y_);
    cairo_line_to(cr, to_.x_, to_.y_);
    cairo_stroke(cr);
    return to_;
}

Rectangle::Rectangle(Point top_left, Point bottom_right):top_left_(top_left),bottom_right_(bottom_right)
{
}
Point Rectangle::Draw(cairo_t* cr)
{
    cairo_rectangle(cr, top_left_.x_, top_left_.y_,
                    bottom_right_.x_ - top_left_.x_,
                    bottom_right_.y_ - top_left_.y_);
    cairo_stroke(cr);
    return bottom_right_;
}
